/*
 *      File:              /room/clean.c
 *      Function:          Performs room cleaning.     
 *      Author(s):         Earwax@Nirvana
 *      Copyright:         Copyright (c) 2004 Earwax/David Halek
 *                                 All Rights Reserved.
 *      Source:            03/17/06
 *      Notes:             This should be called by the driver.
 *      Change History:    03/17/06:  recoded, added check for
 *                         players being in room.
 *****************************************************************
 */

/* Global Variables */
int no_clean,     /* 1 means don't clean here   */
    cast_here;    /* Room is safe to destruct() */

/* Parameters */
set_no_clean(arg){ no_clean = arg; }

/* 
 * Function name:  clean_up: 
 * Description:    called by the driver to clean a room 
 * Returns:        0 : never call cleanup on this object again
 *                 1 : always returns 1, heh
 */

clean_up() 
{
  cast_here = 0; 
  /* log_file("CLEAN",file_name(this_object())+" room Cleaned.\n"); */
  if(no_clean || present("GlobalPlayerId", this_object())) return 1;
  dest_inv();
  if(!cast_here) destruct(this_object());
  return 1;
}

/* 
 * Function name: dest_inv
 * Description:   Nuke the inventory of this object
 * Returns:       1
 */

dest_inv()
{
  object ob, ob2;

  ob = first_inventory(this_object());

  while(ob)
  {
    ob2 = next_inventory(ob);

    if ((int)ob->is_castle()) 
    {
      cast_here = 1;
      return 1;
    }
    if ( !((status)ob->query_interactive()) )
      destruct(ob);

    ob = ob2;
  }
  return 1;
}


